package com.fowo.api.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.R;
import com.fowo.api.sys.model.SysLoginLogItemVo;
import com.fowo.api.sys.model.SysLoginLogSearch;
import com.fowo.api.sys.service.SysLoginLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/sys/login/log")
public class SysLoginLogController {
    @Resource
    private SysLoginLogService sysLoginLogService;

    @GetMapping("page")
    public R<Page<SysLoginLogItemVo>> page(SysLoginLogSearch search) {
        return R.data(() -> sysLoginLogService.searchPage(search));
    }

    @DeleteMapping("clean")
    @PreAuthorize("@am.canAccess('sysLoginLogClean')")
    public R clean() {
        return R.ok(() -> sysLoginLogService.clean());
    }
}
